// hyb_yl/twosubpages/pages/publicProblems/publicProblems.js
var app = getApp()
var adds = {};
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: !0,
    tabindex: -1,
    keshi: "",
    label: "",
    proain: false,
    isshow: 1,
    showt: '展开',
    page: 0,
    pagesize: 10,
    keyword: "",
    list: [],
    deparshow: false,
  },
  // 选择科室
  departab: function (e) {
    // console.log(e);
    var that = this;
    const index = e.currentTarget.dataset.dex;
    var id = e.currentTarget.dataset.id;
    that.setData({
      isLoading: !0,
    })
    app.util.request({
      'url': "entry/wxapp/answer.labels",
      data: {
        id: id
      },
      success: function (res) {
        that.setData({
          label_arr: res.data,
          tabindex: index,
          deparshow: false,
          isLoading: !1,
        })
      }
    })
    that.setData({
      list:[],
      page:0
    })
    that.getAnswer(that.data.keyword, id, '')
    if (id == '0') {
      this.getAnswer('','','')
    }
    this.setData({
      keshi: id
    })
  },
  // 选择标签
  label_change: function (e) {
    var that = this;
    var label = e.currentTarget.dataset.title;
    that.setData({
      label: label
    })
    that.setData({
      page: 0,
      list: []
    })
    var keyword = that.data.keyword;
    var keshi = that.data.keshi;
    that.getAnswer(keyword, keshi, label)
  },
  opend: function () {
    if (this.data.isshow == 0) {
      this.setData({
        isshow: 1,
        showt: '展开'
      })
    } else {
      this.setData({
        isshow: 0,
        showt: '收起'
      })
    }
  },
  proaInfor: function (e) {
    var id = e.currentTarget.dataset.id;
    var typs = e.currentTarget.dataset.typs;
    var state = e.currentTarget.dataset.state
    wx.navigateTo({
      url: '/hyb_yl/twosubpages/pages/publicProblemsInfor/publicProblemsInfor?id=' + id + '&typs=' + typs + '&state=' + state,
    })
  },
  deparlist: function () {
    if (this.data.deparshow) {
      this.setData({
        deparshow: false
      })
    } else {
      this.setData({
        deparshow: true
      })
    }
  },
  departabs: function (e) {
    // console.log(e);
    const index = e.currentTarget.dataset.dex;
    this.setData({
      tabindex: index,
      deparshow: false
    })
  },
  scrolltoupper: function (e) {
    console.log(e);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.getKeshi();
    var tabindex = options.tabindex
    if(tabindex != undefined && tabindex != 'undefined')
    {
      that.setData({
        tabindex: tabindex
      })
    }else{
      that.setData({
        tabindex: -1
      })
    }
    console.log(that.data.tabindex)
    that.getAnswer('', '', '');
  },
  changekeyword: function (e) {
    var that = this;
    var keyword = e.detail.value;
    that.setData({
      keyword: keyword
    })

  },
  searchs: function () {
    var that = this;
    that.setData({
      list: [],
      page: 0
    })

    that.getAnswer(that.data.keyword, that.data.keshi, that.data.label)
  },
  // 获取问题列表
  getAnswer: function (keyword, keshi, label) {
    var that = this;
  
    app.util.request({
      'url': "entry/wxapp/answer.lists",
      data: {
        page: that.data.page,
        pagesize: that.data.pagesize,
        keyword: keyword,
        keshi: keshi,
        label: label
      },
      success: function (res) {
        console.log(res)
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: page,
          isLoading: !1
        });

      }
    })
  },
  // 获取科室列表
  getKeshi: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/answer.keshi_arr",
      success: function (res) {
        that.setData({
          keshi_arr: res.data
        })
        // app.util.request({
        //   'url': "entry/wxapp/answer.labels",
        //   data: {
        //     id: res.data[0].id
        //   },
        //   success: function (res) {
        //     that.setData({
        //       label_arr: res.data
        //     })
        //   }
        // })
        // that.setData({
        //   keshi: res.data[0].id
        // })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var keyword = that.data.keyword;
    var label = that.data.label;
    var keshi = that.data.keshi;
    that.getAnswer(keyword, label, keshi)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})